#include <iostream>
#include <map>
#include <string>
using namespace std;

string get_string(string json, int& index);
void section_deal(string pre_string, string json, int& index, map<string, string>& query_json);

int main(int argc, char const* argv[])
{
    map<string, string> query_json;
    string json;
    int n, m;
    cin >> n >> m;
    cin.ignore();
    for (int i = 0; i < n; i++) {
        string temp;
        getline(cin, temp);
        json += temp;
    }
    int t = json.find(" ", 0);
    while (t != string::npos) {
        json.erase(t, 1);
        t = json.find(" ", 0);
    }
    t = json.find(",", 0);
    while (t != string::npos) {
        json.erase(t, 1);
        t = json.find(",", 0);
    }

    string pre_string = "";
    int deal_index = 0;

    section_deal(pre_string, json, deal_index, query_json);

    for (int i = 0; i < m; i++) {
        string query;
        cin >> query;
        string output = "NOTEXIST";
        map<string, string>::iterator iter = query_json.begin();
        while (iter != query_json.end()) {
            if (query == iter->first) {
                output = "STRING " + iter->second;
                break;
            } else if (iter->first.find(query + ".", 0) != string::npos) {
                output = "OBJECT";
                break;
            }
            iter++;
        }
        cout << output << endl;
    }
    return 0;
}

string get_string(string json, int& index)
{
    string return_string = "";
    while (json[index] != '"') {
        if (json[index] == '\\') {
            return_string += json[++index];
            index++;
        } else {
            return_string += json[index];
            index++;
        }
    }
    index++;
    return return_string;
}

void section_deal(string pre_string, string json, int& index, map<string, string>& query_json)
{
    if (json[index] == '{')
        index++;
    while (json[index] != '}') {
        index++;
        string temp_pre_string = get_string(json, index);
        string current_pre_string = pre_string + temp_pre_string;
        index++;
        if (json[index] == '"') {
            index++;
            string content = get_string(json, index);
            query_json[current_pre_string] = content;
            int t = current_pre_string.find(temp_pre_string, 0);
            current_pre_string.erase(t, temp_pre_string.size());
        } else if (json[index] == '{') {
            current_pre_string += ".";
            section_deal(current_pre_string, json, index, query_json);
            index++;
        }
    }
}